package com.sky.controller.admin;

import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.dto.PageDto;
import com.sky.result.PageBean;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/admin/order")
@Slf4j
@RestController
@Api("商家端管理")
public class OrderController {
    @Autowired
    OrderService orderService;

    /**
     * 订单搜索
     */
    @GetMapping("/conditionSearch")
    public Result conditionSearch(PageDto pageDto) {
        log.info("订单搜索{}", pageDto);
        PageBean<OrderVO> orderVOPageBean = orderService.search(pageDto);
        return Result.success(orderVOPageBean);

    }

    /**
     * 订单数量查询
     *
     * @return
     */
    @GetMapping("/statistics")
    public Result statistics() {
        log.info("订单状态数量统计");
        OrderStatisticsVO orderStatisticsVO = orderService.count();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 订单详情查询
     */
    @GetMapping("/details/{id}")
    public Result selectDetails(@PathVariable long id) {
        log.info("查询订单详情{}", id);
        OrderVO orderVO = orderService.selectDatails(id);
        return Result.success(orderVO);
    }

    /**
     * 接单
     */
    @PutMapping("/confirm")
    public Result confirmOrder(@RequestBody  OrdersRejectionDTO ordersRejectionDTO){
        log.info("接单{}", ordersRejectionDTO.getId());
        orderService.confirmOrder(ordersRejectionDTO.getId());
        return Result.success();
    }

    /**
     * 取消订单
     */
    @PutMapping("/cancel")
    public Result cancelOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        log.info("取消订单{}", ordersRejectionDTO);
        orderService.adminCancelOrder(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 拒绝订单
     */
    @PutMapping("/rejection")
    public Result rejectionOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        log.info("取消订单{}", ordersRejectionDTO);
        orderService.adminRejectionOrder(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 完单
     */
    @PutMapping("/complete/{id}")
    public Result completeOrder(@PathVariable long id) {
        log.info("商家完成订单{}", id);
        orderService.completeOrder(id);
        return Result.success();
    }
    /**
     * 派单
     */
    @PutMapping("/delivery/{id}")
    public Result deliveryOrder(@PathVariable long id) {
        log.info("商家派送订单{}", id);
        orderService.sendOrder(id);
        return Result.success();
    }


}
